package com.wing.product.service;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wing.bill.model.response.MaterialStatisticsListVO;
import com.wing.bill.model.response.MaterialStatisticsVO;
import com.wing.product.dao.CabProductDetailDao;
import com.wing.product.model.entity.*;
import com.wing.product.model.request.ProductDetailForm;
import com.wing.product.model.response.ProductDetailVO;
import com.wing.product.model.response.ProductVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.*;

/**
 * 产品明细表-ServiceImpl
 *
 * @author
 */
@Service
@Slf4j
public class ProductDetailServiceImpl extends ServiceImpl<CabProductDetailDao, ProductDetail> implements ProductDetailService {



    @Override
    public int add(ProductDetailForm productDetailForm) {

        //校验

        ProductDetail productDetail =new ProductDetail();
        CopyOptions copyOptions = CopyOptions.create()
        .setEditable(ProductDetail.class)
        .setIgnoreError(true)
        .setIgnoreNullValue(true);
        BeanUtil.copyProperties(productDetailForm, productDetail, copyOptions);

        return baseMapper.insert(productDetail);
    }

    @Override
    public List<ProductDetailVO> list4app(Map<String, Object> params) {
        return baseMapper.list4app(params);
    }

    @Override
    public Page<ProductDetailVO> pageList4app(Page page, Map<String, Object> params) {
        List<ProductDetailVO> list = baseMapper.list4app(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public ProductDetailVO get4appById(Long id) {
        return baseMapper.get4appById(id);
    }

    @Override
    public ProductDetailVO getProductDetailBySkuCode(String skuCode) {
        return baseMapper.getProductDetailBySkuCode(skuCode);
    }

    @Override
    public ProductDetailVO getProductInfoBySkuCode(String skuCode) {
        return baseMapper.getProductInfoBySkuCode(skuCode);
    }

    @Override
    public Page<ProductVO> productList(Page page, Map<String, Object> params) {
        List<ProductDetailVO> list = baseMapper.productList(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public List<ProductDetailVO> getProductDetailByInoutType(Integer inoutType) {
        return baseMapper.getProductDetailByInoutType(inoutType);
    }

    @Override
    public Page<ProductDetailVO> findWarningOfProcurement(Page page, Map<String, Object> params) {
        List<ProductDetailVO> list = baseMapper.findWarningOfProcurement(page, params);
        page.setRecords(list);
        return page;
    }

    @Override
    public Integer countProductTypes(List<String> skuCodes) {
        return baseMapper.countProductTypes(skuCodes);
    }

    @Override
    public Integer updateWeightUnit(BigDecimal weight, Long id) {
        return baseMapper.updateWeightUnit(weight,id);
    }

    @Override
    public List<ProductDetail> listBySkuCode(String skuCode) {
        return baseMapper.list4SkuCode(skuCode);
    }

    @Override
    public List<MaterialStatisticsListVO> materialStatisticsReport(Map<String, Object> params) {
        return baseMapper.materialStatisticsReport(params);
    }

    @Override
    public List<MaterialStatisticsVO> materialGetNewStatistics(Map<String, Object> params) {
        return baseMapper.materialGetNewStatistics(params);
    }

    @Override
    public List<MaterialStatisticsVO> materialNoReturnStatistics(Map<String, Object> params) {
        return baseMapper.materialNoReturnStatistics(params);
    }

    @Override
    public List<MaterialStatisticsVO> materialTemporaryStorageStatistics(Map<String, Object> params) {
        return baseMapper.materialTemporaryStorageStatistics(params);
    }

    @Override
    public List<MaterialStatisticsVO> materialRepairStatistics(Map<String, Object> params) {
        return baseMapper.materialRepairStatistics(params);
    }

    @Override
    public List<MaterialStatisticsVO> materialScrapStatistics(Map<String, Object> params) {
        return baseMapper.materialScrapStatistics(params);
    }

    @Override
    public List<MaterialStatisticsVO> materialLossStatistics(Map<String, Object> params) {
        return baseMapper.materialLossStatistics(params);
    }

    @Override
    public List<MaterialStatisticsVO> materialAbnormalStatistics(Map<String, Object> params) {
        return baseMapper.materialAbnormalStatistics(params);
    }
}
